| 1 |
/* @(#)error.c 19.1 (ES0-DMD) 02/25/03 13:58:13 */ |
| 2 |
/*=========================================================================== |
| 3 |
Copyright (C) 1995 European Southern Observatory (ESO) |
| 4 |
|
| 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. |
| 9 |
|
| 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. |
| 14 |
|
| 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, |
| 18 |
MA 02139, USA. |
| 19 |
|
| 20 |
Corresponding concerning ESO-MIDAS should be addressed as follows: |
| 21 |
Internet e-mail: [email protected] |
| 22 |
Postal address: European Southern Observatory |
| 23 |
Data Management Division |
| 24 |
Karl-Schwarzschild-Strasse 2 |
| 25 |
D 85748 Garching bei Muenchen |
| 26 |
GERMANY |
| 27 |
===========================================================================*/ |
| 28 |
|
| 29 |
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 30 |
|
| 31 |
.TYPE Module |
| 32 |
.IDENTIFICATION error.c |
| 33 |
.AUTHOR Alan Richmond [ST-ECF] |
| 34 |
.LANGUAGE C |
| 35 |
.KEYWORDS Error handling. |
| 36 |
.ENVIRONMENT |
| 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 |
| 51 |
Added eh_loc_error. |
| 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... |
| 59 |
|
| 60 |
-----------------------------*/ |
| 61 |
|
| 62 |
#include <osdefos.h> |
| 63 |
#include <macrogen.h> |
| 64 |
#include <error.h> |
| 65 |
#include <string.h> |
| 66 |
|
| 67 |
#define LINESIZE (sizeof(locbuf)-1) |
| 68 |
/* Maximum size of a line */ |
| 69 |
|
| 70 |
static char locbuf[81]=""; |
| 71 |
static char error_state = 0; |
| 72 |
static char avoid[] = ""; |
| 73 |
static int keep_bytes = 0; /* To be sure to get complete message */ |
| 74 |
static int error_lev = _ERROR_; /* Error or Warning Level */ |
| 75 |
|
| 76 |
/*==========================================================================*/ |
| 77 |
static int edval (x, i) |
| 78 |
/*+++ |
| 79 |
.PURPOSE Edit the long integer number |
| 80 |
.RETURNS The new index in locbuf |
| 81 |
.REMARKS |
| 82 |
--------*/ |
| 83 |
long int x; /* IN: Number ot edit */ |
| 84 |
int i; /* IN: Index in locbuf */ |
| 85 |
{ |
| 86 |
register int k; |
| 87 |
register long int j; |
| 88 |
MID_STATIC char edbuf[12] = " "; |
| 89 |
|
| 90 |
j = ABSOLUTE(x); |
| 91 |
|
| 92 |
for (k = sizeof(edbuf); ;) |
| 93 |
{ edbuf[--k]= (j%10) + '0'; |
| 94 |
j /= 10; |
| 95 |
if (j == 0) break; |
| 96 |
} |
| 97 |
if (x < 0) edbuf[--k] = '-'; |
| 98 |
|
| 99 |
i += oscopy(&locbuf[i], &edbuf[k], sizeof(edbuf)-k); |
| 100 |
return(i); |
| 101 |
} |
| 102 |
|
| 103 |
/*=========================================================================*/ |
| 104 |
/* Public Routines */ |
| 105 |
/*=========================================================================*/ |
| 106 |
int eh_state () |
| 107 |
/*+++ |
| 108 |
.PURPOSE Test for error state, i.e. any error was reported, and not yet cleared |
| 109 |
.RETURNS 0 if no error, 1 if error exists. |
| 110 |
---------*/ |
| 111 |
{ |
| 112 |
return(error_state); |
| 113 |
} |
| 114 |
|
| 115 |
/*=========================================================================*/ |
| 116 |
int eh_class (class) |
| 117 |
/*+++ |
| 118 |
.PURPOSE Define error level for next message |
| 119 |
.RETURNS error state |
| 120 |
.REMARKS Class is _ERROR_ or _WARNING_ |
| 121 |
---------*/ |
| 122 |
int class; /* _ERROR_ or _WARNING_ */ |
| 123 |
{ |
| 124 |
error_lev = class; |
| 125 |
|
| 126 |
return(error_state); |
| 127 |
} |
| 128 |
|
| 129 |
/*=========================================================================*/ |
| 130 |
int eh_put (subr, message, class) |
| 131 |
/*+++ |
| 132 |
.PURPOSE Store error message. |
| 133 |
.RETURNS 0 (Not an error) / 1 (Is a error) |
| 134 |
.REMARKS Class is _ERROR_ or _WARNING_ |
| 135 |
---------*/ |
| 136 |
char *subr; /* IN: subroutine name (unused) */ |
| 137 |
char *message; /* IN: message text */ |
| 138 |
int class; /* _ERROR_ or _WARNING_ */ |
| 139 |
{ |
| 140 |
return(eh_put2(subr, message, class, strlen(message))); |
| 141 |
} |
| 142 |
|
| 143 |
/*=========================================================================*/ |
| 144 |
int eh_put1(message) |
| 145 |
/*+++ |
| 146 |
.PURPOSE Store error message. |
| 147 |
.RETURNS 0 (Not an error) / 1 (Is a error) |
| 148 |
.REMARKS Class is _ERROR_ |
| 149 |
---------*/ |
| 150 |
char *message; /* IN: message text */ |
| 151 |
{ |
| 152 |
return(eh_put2((char *)0, message, _ERROR_, strlen(message))); |
| 153 |
} |
| 154 |
|
| 155 |
/* ARGSUSED */ |
| 156 |
/*=========================================================================*/ |
| 157 |
int eh_put2 (subr, message, class, lmsg) |
| 158 |
/*+++ |
| 159 |
.PURPOSE Store error message. |
| 160 |
.RETURNS 0 (Not an error) / 1 (Is a error) |
| 161 |
.REMARKS Class is _ERROR_ or _WARNING_ |
| 162 |
---------*/ |
| 163 |
char *subr; /* IN: subroutine name (unused) */ |
| 164 |
char *message; /* IN: message text */ |
| 165 |
int class; /* _ERROR_ or _WARNING_ */ |
| 166 |
int lmsg; /* IN: Length of message */ |
| 167 |
{ |
| 168 |
register char *p; |
| 169 |
register int i; |
| 170 |
|
| 171 |
if (!message) return(0); /* No message at all ... */ |
| 172 |
|
| 173 |
pm_tr2(class, message, lmsg); |
| 174 |
|
| 175 |
if (message != locbuf) |
| 176 |
{ for (p = message, i = 0; (i < LINESIZE) && (*p); ) |
| 177 |
locbuf[i++] = *(p++); |
| 178 |
locbuf[i] = EOS; |
| 179 |
} |
| 180 |
|
| 181 |
if(class == _ERROR_) error_state = 1; |
| 182 |
|
| 183 |
error_lev = _ERROR_; /* Error or Warning Level */ |
| 184 |
|
| 185 |
return(error_state); |
| 186 |
} |
| 187 |
|
| 188 |
/*=========================================================================*/ |
| 189 |
/* ARGSUSED */ |
| 190 |
char *eh_loc (level, subr, class) |
| 191 |
/*+++ |
| 192 |
.PURPOSE Retrieve address of a stored error message |
| 193 |
.RETURNS Address of message / NULL if no message |
| 194 |
.REMARKS |
| 195 |
---------*/ |
| 196 |
int level; /* TBD */ |
| 197 |
char *subr; /* OUT: subroutine name (unused) */ |
| 198 |
int class; /* TBD */ |
| 199 |
{ |
| 200 |
return (error_state ? locbuf : NULL_PTR(char)); |
| 201 |
} |
| 202 |
|
| 203 |
/*=========================================================================*/ |
| 204 |
/* ARGSUSED */ |
| 205 |
int eh_clear (level) |
| 206 |
/*+++ |
| 207 |
.PURPOSE Clear error state. |
| 208 |
.RETURNS 0 |
| 209 |
.REMARKS |
| 210 |
---------*/ |
| 211 |
int level; /* TBD */ |
| 212 |
{ |
| 213 |
error_state = 0; |
| 214 |
return(error_state); |
| 215 |
} |
| 216 |
|
| 217 |
/*************************************************************************** |
| 218 |
* eh_ed routines |
| 219 |
****************************************************************************/ |
| 220 |
|
| 221 |
static int eh_ed0(text) |
| 222 |
/*+++ |
| 223 |
.PURPOSE Copies the text to internal buffer |
| 224 |
.RETURNS Index of first useable character in internal buffer |
| 225 |
.REMARKS Routine not traced. Leaves at least keep_bytes. |
| 226 |
---------*/ |
| 227 |
char *text; /* IN: text to copy */ |
| 228 |
{ |
| 229 |
register int i, l; |
| 230 |
register char *p; |
| 231 |
|
| 232 |
l = LINESIZE - keep_bytes; |
| 233 |
for (i=0, p=text; (i < l) && (*p); ) |
| 234 |
locbuf[i++] = *(p++); |
| 235 |
if ( (*p == '\0') && (*(p-1) != ' ')) |
| 236 |
locbuf[i++] = ' '; /* Add blank */ |
| 237 |
|
| 238 |
if ( (*p) && (i >= 4) ) /* Too long text... */ |
| 239 |
{ p = &locbuf[i-4]; |
| 240 |
*(p++) = '.', *(p++) = '.', *(p++) = '.'; |
| 241 |
*(p++) = ' '; |
| 242 |
} |
| 243 |
|
| 244 |
return(i); |
| 245 |
} |
| 246 |
|
| 247 |
/*=========================================================================*/ |
| 248 |
int eh_ed_as(text, string) |
| 249 |
/*+++ |
| 250 |
.PURPOSE Error: text followed by EOS string |
| 251 |
.RETURNS 1 |
| 252 |
.REMARKS string can be a null pointer. |
| 253 |
---------*/ |
| 254 |
char *text; /* IN: Text to insert */ |
| 255 |
char *string; /* IN: String to insert, terminated with EOS */ |
| 256 |
{ |
| 257 |
char *p; |
| 258 |
|
| 259 |
p = (string ? string : "<NuLL>"); |
| 260 |
|
| 261 |
return(eh_ed_str2(text, p, strlen(p))); |
| 262 |
} |
| 263 |
|
| 264 |
/*=========================================================================*/ |
| 265 |
int eh_ed_str2 (text, string, length) |
| 266 |
/*+++ |
| 267 |
.PURPOSE Error: text followed by string |
| 268 |
.RETURNS 1 |
| 269 |
.REMARKS Routine not traced |
| 270 |
---------*/ |
| 271 |
char *text; /* IN: Text to insert */ |
| 272 |
char *string; /* IN: String to insert */ |
| 273 |
int length; /* IN: length of string */ |
| 274 |
{ |
| 275 |
register int i, l; |
| 276 |
register char *p; |
| 277 |
|
| 278 |
keep_bytes = length; |
| 279 |
|
| 280 |
i = eh_ed0(text); |
| 281 |
|
| 282 |
for (p = string, l = length; (i < LINESIZE) && (--l >= 0) ; ) |
| 283 |
locbuf[i++] = *(p++); |
| 284 |
|
| 285 |
locbuf[i] = EOS; |
| 286 |
|
| 287 |
return(eh_put2(avoid, locbuf, error_lev, i)); |
| 288 |
} |
| 289 |
|
| 290 |
/*=========================================================================*/ |
| 291 |
int eh_ed_i (text, value) |
| 292 |
/*++++++++ |
| 293 |
.PURPOSE Store error message followed by a number. |
| 294 |
.RETURNS 1 |
| 295 |
.REMARKS Routine not traced |
| 296 |
---------*/ |
| 297 |
char *text; /* IN: EOS-terminated Text to insert*/ |
| 298 |
int value; /* IN: value to edit */ |
| 299 |
{ |
| 300 |
register int i; |
| 301 |
long int x; |
| 302 |
|
| 303 |
keep_bytes = 11; |
| 304 |
i = eh_ed0(text); |
| 305 |
|
| 306 |
if (i < LINESIZE - 11) |
| 307 |
{ x = value; |
| 308 |
i = edval(x, i); |
| 309 |
} |
| 310 |
locbuf[i] = EOS; |
| 311 |
|
| 312 |
return(eh_put2(avoid, locbuf, error_lev, i)); |
| 313 |
} |
| 314 |
|