~ubuntu-branches/ubuntu/wily/eso-midas/wily-proposed

« back to all changes in this revision

Viewing changes to libsrc/astro/ast_error.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* @(#)ast_error.c      19.1 (ES0-DMD) 02/25/03 13:53:53 */
 
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: midas@eso.org
 
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
 
 
66
#define         LINESIZE        (sizeof(locbuf)-1)
 
67
                                                /* Maximum size of a line   */
 
68
 
 
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 */
 
74
 
 
75
/*==========================================================================*/
 
76
static int edval (x, i)
 
77
/*+++
 
78
.PURPOSE Edit the long integer number
 
79
.RETURNS The new index in locbuf
 
80
.REMARKS 
 
81
--------*/
 
82
        long int x;     /* IN: Number ot edit   */
 
83
        int i;          /* IN: Index in locbuf  */
 
84
{
 
85
        register int k;
 
86
        register long int j;
 
87
        STATIC char edbuf[12] = "           ";
 
88
 
 
89
  j = ABSOLUTE(x);
 
90
  
 
91
  for (k = sizeof(edbuf); ;)
 
92
  {     edbuf[--k]= (j%10) + '0';
 
93
        j /= 10;
 
94
        if (j == 0)     break;
 
95
  }
 
96
  if (x < 0)    edbuf[--k] = '-';
 
97
  
 
98
  i += oscopy(&locbuf[i], &edbuf[k], sizeof(edbuf)-k);
 
99
  return(i);
 
100
}
 
101
 
 
102
/*=========================================================================*/
 
103
/*                      Public Routines                                    */
 
104
/*=========================================================================*/
 
105
int eh_state ()
 
106
/*+++
 
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.
 
109
---------*/
 
110
{
 
111
  return(error_state);
 
112
}
 
113
 
 
114
/*=========================================================================*/
 
115
int eh_class (class)
 
116
/*+++
 
117
.PURPOSE Define error level for next message
 
118
.RETURNS error state
 
119
.REMARKS Class is _ERROR_ or _WARNING_
 
120
---------*/
 
121
        int      class;         /* _ERROR_ or _WARNING_         */
 
122
{
 
123
  error_lev = class;
 
124
  
 
125
  return(error_state);
 
126
}
 
127
 
 
128
/*=========================================================================*/
 
129
int eh_put (subr, message, class)
 
130
/*+++
 
131
.PURPOSE Store error message.
 
132
.RETURNS 0 (Not an error) / 1 (Is a error)
 
133
.REMARKS Class is _ERROR_ or _WARNING_
 
134
---------*/
 
135
        char     *subr;         /* IN: subroutine name (unused) */
 
136
        char     *message;      /* IN: message text     */
 
137
        int      class;         /* _ERROR_ or _WARNING_         */
 
138
{
 
139
  return(eh_put2(subr, message, class, strlen(message)));
 
140
}
 
141
 
 
142
/*=========================================================================*/
 
143
int eh_put2 (subr, message, class, lmsg)
 
144
/*+++
 
145
.PURPOSE Store error message.
 
146
.RETURNS 0 (Not an error) / 1 (Is a error)
 
147
.REMARKS Class is _ERROR_ or _WARNING_
 
148
---------*/
 
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        */
 
153
{
 
154
        register char *p;
 
155
        register int  i;
 
156
 
 
157
  if (!message)         return(0);      /* No message at all ... */
 
158
 
 
159
  pm_tr2(class, message, lmsg);
 
160
 
 
161
  if (message != locbuf)
 
162
  {     for (p = message, i = 0; (i < LINESIZE) && (*p); )
 
163
                locbuf[i++] = *(p++);
 
164
          locbuf[i] = EOS;
 
165
  }
 
166
 
 
167
  if(class == _ERROR_)  error_state = 1;
 
168
 
 
169
  error_lev  = _ERROR_;         /* Error or Warning Level */
 
170
 
 
171
  return(error_state);
 
172
}
 
173
 
 
174
/*=========================================================================*/
 
175
char *eh_loc (level, subr, class)
 
176
/*+++
 
177
.PURPOSE Retrieve address of a stored error message
 
178
.RETURNS Address of message / NULL if no message
 
179
.REMARKS 
 
180
---------*/
 
181
        int     level;                  /* TBD  */
 
182
        char    *subr;          /* OUT: subroutine name (unused)        */
 
183
        int     class;                  /* TBD  */
 
184
{
 
185
  return (error_state ? locbuf : NULL_PTR(char));
 
186
}
 
187
 
 
188
/*=========================================================================*/
 
189
int eh_clear (level)
 
190
/*+++
 
191
.PURPOSE Clear error state.
 
192
.RETURNS 0
 
193
.REMARKS 
 
194
---------*/
 
195
        int      level;         /* TBD  */
 
196
{
 
197
  error_state = 0;
 
198
  return(error_state);
 
199
}
 
200
 
 
201
/***************************************************************************
 
202
 *                      eh_ed routines
 
203
 ****************************************************************************/
 
204
 
 
205
static int eh_ed0(text)
 
206
/*+++
 
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.
 
210
---------*/
 
211
        char *text;     /* IN: text to copy     */
 
212
{
 
213
        register int    i, l;
 
214
        register char   *p;
 
215
 
 
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 */
 
221
 
 
222
  if ( (*p) && (i >= 4) )               /* Too long text... */
 
223
  {     p = &locbuf[i-4];
 
224
        *(p++) = '.', *(p++) = '.', *(p++) = '.';
 
225
        *(p++) = ' ';
 
226
  }
 
227
 
 
228
  return(i);
 
229
}
 
230
 
 
231
/*=========================================================================*/
 
232
int eh_ed_as(text, string)
 
233
/*+++
 
234
.PURPOSE Error: text followed by EOS string
 
235
.RETURNS 1
 
236
.REMARKS string can be a null pointer.
 
237
---------*/
 
238
        char    *text;          /* IN: Text to insert   */
 
239
        char    *string;        /* IN: String to insert, terminated with EOS */
 
240
{
 
241
        char    *p;
 
242
 
 
243
  p = (string ? string : "<NuLL>");
 
244
 
 
245
  return(eh_ed_str2(text, p, strlen(p)));
 
246
}
 
247
 
 
248
/*=========================================================================*/
 
249
int eh_ed_str2  (text, string, length)
 
250
/*+++
 
251
.PURPOSE Error: text followed by string
 
252
.RETURNS 1
 
253
.REMARKS Routine not traced
 
254
---------*/
 
255
        char    *text;                  /* IN: Text to insert   */
 
256
        char    *string;                /* IN: String to insert */
 
257
        int     length;                 /* IN: length of string */
 
258
{
 
259
        register int i, l;
 
260
        register char *p;
 
261
 
 
262
  keep_bytes = length;
 
263
  
 
264
  i = eh_ed0(text);
 
265
 
 
266
  for (p = string, l = length; (i < LINESIZE) && (--l >= 0) ; )
 
267
        locbuf[i++] = *(p++);
 
268
 
 
269
  locbuf[i] = EOS;
 
270
 
 
271
  return(eh_put2(avoid, locbuf, error_lev, i));
 
272
}
 
273
 
 
274
/*=========================================================================*/
 
275
int eh_ed_i (text, value)
 
276
/*++++++++
 
277
.PURPOSE Store error message followed by a number.
 
278
.RETURNS 1
 
279
.REMARKS Routine not traced
 
280
---------*/
 
281
        char    *text;                  /* IN: EOS-terminated Text to insert*/
 
282
        int     value;                  /* IN: value to edit            */
 
283
{
 
284
        register int i;
 
285
        long int x;
 
286
 
 
287
  keep_bytes = 11;
 
288
  i = eh_ed0(text);
 
289
 
 
290
  if (i < LINESIZE - 11)        
 
291
  {     x = value;
 
292
        i = edval(x, i);
 
293
  }
 
294
  locbuf[i] = EOS;
 
295
 
 
296
  return(eh_put2(avoid, locbuf, error_lev, i));
 
297
}
 
298