| 1 |
/*=========================================================================== |
| 2 |
Copyright (C) 1988-2009 European Southern Observatory (ESO) |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU General Public License as |
| 6 |
published by the Free Software Foundation; either version 2 of |
| 7 |
the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public |
| 15 |
License along with this program; if not, write to the Free |
| 16 |
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge, |
| 17 |
MA 02139, USA. |
| 18 |
|
| 19 |
Corresponding concerning ESO-MIDAS should be addressed as follows: |
| 20 |
Internet e-mail: [email protected] |
| 21 |
Postal address: European Southern Observatory |
| 22 |
Data Management Division |
| 23 |
Karl-Schwarzschild-Strasse 2 |
| 24 |
D 85748 Garching bei Muenchen |
| 25 |
GERMANY |
| 26 |
===========================================================================*/ |
| 27 |
|
| 28 |
/*+++++++++ |
| 29 |
.MODULE trerror.c |
| 30 |
.AUTHOR Francois Ochsenbein [ESO] |
| 31 |
.LANGUAGE C |
| 32 |
.CATEGORY Error handler for Conversions char <-> binary |
| 33 |
|
| 34 |
.COMMENTS This implementation passes the error to the general error handler. |
| 35 |
It's possible to change the tr_error routine. |
| 36 |
.VERSION 1.0 13-Oct-1988: Creation |
| 37 |
.VERSION 1.0 11-May-1990: Added Morphological Class |
| 38 |
|
| 39 |
090831 last modif |
| 40 |
-------------------------*/ |
| 41 |
|
| 42 |
#include <midas_def.h> /* For classes of memory (readonly) */ |
| 43 |
#include <error.h> |
| 44 |
#include <tra.h> |
| 45 |
#include <macrogen.h> |
| 46 |
#include <string.h> |
| 47 |
|
| 48 |
|
| 49 |
extern int eh_put1(); |
| 50 |
|
| 51 |
|
| 52 |
MID_STATIC struct trerr_s errs = { |
| 53 |
0, NULL_PTR(char), NULL_PTR(char), 0, 0}; |
| 54 |
|
| 55 |
MID_GLOBAL struct trerr_s *trerror = &errs; |
| 56 |
|
| 57 |
MID_RSTATIC char *errlist[] = { |
| 58 |
"", /* TRERR_OK */ |
| 59 |
"Digit", /* TRERR_DIGIT */ |
| 60 |
"Octal", /* TRERR_OCTAL */ |
| 61 |
"Hexadecimal", /* TRERR_HEXA */ |
| 62 |
"Floating number", /* TRERR_FLOAT */ |
| 63 |
"Too large number", /* TRERR_TOOLARGE */ |
| 64 |
"Too small number", /* TRERR_TOOSMALL */ |
| 65 |
"Too many numbers", /* TRERR_TOOMANY */ |
| 66 |
"Too few numbers", /* TRERR_TOOFEW */ |
| 67 |
"No number", /* TRERR_VOID */ |
| 68 |
"Sexagesimal", /* TRERR_SEXA */ |
| 69 |
"Spectral Temp. Class", /* TRERR_SPT */ |
| 70 |
"Spectral Lum. Class", /* TRERR_SPL */ |
| 71 |
"Hubble Morph. Class" /* TRERR_MT */ |
| 72 |
}; |
| 73 |
|
| 74 |
MID_STATIC char *buf = NULL_PTR(char); |
| 75 |
|
| 76 |
#define terminator "? " |
| 77 |
|
| 78 |
#define FINISH goto FIN |
| 79 |
|
| 80 |
/*===========================================================================*/ |
| 81 |
struct trerr_s *tr_errs() |
| 82 |
/*++++++ |
| 83 |
.PURPOSE Get `packet' of last encountered translation error. |
| 84 |
.RETURNS Address of `packet' / NULL if no error |
| 85 |
.REMARKS Error codes are translated to comprehensive messages. |
| 86 |
--------*/ |
| 87 |
{ |
| 88 |
if (errs.errno == 0) return(NULL_PTR(struct trerr_s)); |
| 89 |
|
| 90 |
if (errs.errno > 0) /* Convert code */ |
| 91 |
{ if (errs.errno < ITEMS(errlist)) |
| 92 |
errs.msg = errlist[errs.errno]; |
| 93 |
else errs.errno = TRERR_UNDEF; |
| 94 |
} |
| 95 |
if_not(errs.msg) errs.msg = "Undefined"; |
| 96 |
|
| 97 |
return(&errs); |
| 98 |
} |
| 99 |
|
| 100 |
/*===========================================================================*/ |
| 101 |
int tr_error() |
| 102 |
/*++++++ |
| 103 |
.PURPOSE Log the error message |
| 104 |
.RETURNS Found error number |
| 105 |
.REMARKS Error codes are translated to comprehensive messages. |
| 106 |
--------*/ |
| 107 |
{ |
| 108 |
int l; |
| 109 |
char *p; |
| 110 |
char *osmmexp(); /* Memory allocation */ |
| 111 |
|
| 112 |
if_not(tr_errs()) return(0); |
| 113 |
|
| 114 |
l = strlen(errs.msg); |
| 115 |
buf = osmmexp(buf, l + errs.len + sizeof(terminator) + 2); |
| 116 |
|
| 117 |
p = buf; |
| 118 |
p += oscopy(p, errs.msg, l); |
| 119 |
p += oscopy(p, terminator, sizeof(terminator)-1); |
| 120 |
if (errs.len > 0) |
| 121 |
{ p += oscopy(p, errs.str, errs.offset); |
| 122 |
*(p++) = '^'; |
| 123 |
if (errs.offset < errs.len) |
| 124 |
{ l = errs.offset; |
| 125 |
*(p++) = *(errs.str + l++); |
| 126 |
*(p++) = '^'; |
| 127 |
p += oscopy(p, errs.str + l, errs.len - l); |
| 128 |
} |
| 129 |
} |
| 130 |
*p = '\0'; |
| 131 |
|
| 132 |
ERROR(buf); /* Log message */ |
| 133 |
|
| 134 |
return(errs.errno); |
| 135 |
} |