Skip to content

Commit 990b9b9

Browse files
committed
Add datErmsg
1 parent 390f349 commit 990b9b9

File tree

2 files changed

+287
-0
lines changed

2 files changed

+287
-0
lines changed

Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ datChscn.c \
9090
datClen.c \
9191
datClone.c \
9292
datCopy.c \
93+
datErmsg.c \
9394
datExportFloc.c \
9495
datFind.c \
9596
datGet.c \

datErmsg.c

+286
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
/*
2+
*+
3+
* Name:
4+
* DAT_ERMSG
5+
6+
* Purpose:
7+
* Translate a status value into an error message.
8+
9+
* Language:
10+
* ANSI C
11+
12+
* Invocation:
13+
* CALL DAT_ERMSG( STATUS, LENGTH, MSG )
14+
15+
* Description:
16+
* This routine translates an error status value into an associated
17+
* error message. It first attempts to translate the value supplied
18+
* as a DAT__ error code. If this fails, it then attempts to
19+
* translate it as a system status code for the host operating
20+
* system. If this also fails, then the returned string is a message
21+
* indicating that the status value could not be translated.
22+
23+
* Arguments:
24+
* STATUS = INTEGER (Given)
25+
* The error status value to be translated.
26+
* LENGTH = INTEGER (Returned)
27+
* Number of significant characters in the returned error message
28+
* (i.e. excluding trailing blanks). This value will not exceed
29+
* the length of the character variable supplied for the MSG
30+
* argument.
31+
* MSG = CHARACTER * ( * ) (Returned)
32+
* Buffer of at least EMS__SZMSG+1 bytes to receive the error message.
33+
34+
* Notes:
35+
* - No returned error message will contain more significant
36+
* characters than the value of the EMS__SZMSG symbolic constant.
37+
* This constant is defined in the include file EMS_PAR.
38+
* - The C interface does not check the length of MSG.
39+
40+
* Authors:
41+
* RFWS: R.F. Warren-Smith (STARLINK, RAL)
42+
* BKM: B.K. McIlwrath (STARLINK, RAL)
43+
* TIMJ: Tim Jenness (JAC, Hawaii)
44+
* {enter_new_authors_here}
45+
46+
* Copyright:
47+
* Copyright (C) 1991, 1992, 2000, 2002 SERC/CLRC
48+
* Copyright (C) 2005, 2012 Science & Technology Facilities Council.
49+
* Copyright (C) 2014 Cornell University.
50+
* All Rights Reserved.
51+
52+
53+
* History:
54+
* 5-APR-1991 (RFWS):
55+
* Original portable version.
56+
* 8-APR-1991 (RFWS):
57+
* Improved prologue.
58+
* 13-MAY-1991 (RFWS):
59+
* Added calls to emsMark and emsRlse to prevent use of ems_
60+
* routines from affecting any previously defined message tokens.
61+
* 9-JAN-1992 (RFWS):
62+
* Updated error message for DAT__NOMEM status.
63+
* 1-DEC-1992 (RFWS):
64+
* Added DAT__WLDIN error message.
65+
* 29-OCT-2000 (BKM):
66+
* Revised argument list for full CNF compatability.
67+
* 17-MAY-2002 (BKM):
68+
* Convert to C routine.
69+
* 22-AUG-2002 (BKM):
70+
* Revise C interface and test
71+
* 29-NOV-2005 (TIMJ):
72+
* No reason to pass in a pointer to status.
73+
* Initialise trans. Use size_t for len arg.
74+
* Use modern ems interface.
75+
* 2012-02-23 (TIMJ):
76+
* Fill a supplied buffer rather than returning a pointer to
77+
* stack storage.
78+
* 2014-09-16 (TIMJ):
79+
* Reorganize for HDS-H5.
80+
* {enter_further_changes_here}
81+
82+
* Bugs:
83+
* {note_any_bugs_here}
84+
85+
*-
86+
*/
87+
88+
#include <string.h>
89+
#include <stddef.h>
90+
91+
#include "ems.h" /* EMS error reporting routines */
92+
#include "ems_par.h" /* EMS__ public constants */
93+
94+
#include "dat1.h" /* Internal dat_ definitions */
95+
#include "hds1.h" /* Global definitions for HDS */
96+
97+
#include "dat_err.h" /* DAT__ error code definitions */
98+
#include "sae_par.h"
99+
100+
#include "hds.h"
101+
102+
103+
int
104+
datErmsg(int status, size_t *len, char *msg_str)
105+
{
106+
107+
/* Local Variables: */
108+
const char *trans = NULL; /* Pointer to translation text */
109+
int lstat; /* Local status variable */
110+
int emslen; /* Length from EMS */
111+
112+
/*. */
113+
114+
/* Test for each DAT__ error code, obtaining a pointer to the textual */
115+
/* translation. */
116+
switch ( status )
117+
{
118+
default:
119+
trans = NULL;
120+
break;
121+
122+
case SAI__OK:
123+
trans = "OK, no error (SAI__OK)";
124+
break;
125+
126+
case DAT__LOCIN:
127+
trans = "Locator invalid (DAT__LOCIN)";
128+
break;
129+
130+
case DAT__TYPIN:
131+
trans = "Type invalid (DAT__TYPIN)";
132+
break;
133+
134+
case DAT__NAMIN:
135+
trans = "Name invalid (DAT__NAMIN)";
136+
break;
137+
138+
case DAT__MODIN:
139+
trans = "Mode invalid (DAT__MODIN)";
140+
break;
141+
142+
case DAT__DELIN:
143+
trans = "Deletion invalid (DAT__DELIN)";
144+
break;
145+
146+
case DAT__DIMIN:
147+
trans = "Dimensions invalid (DAT__DIMIN)";
148+
break;
149+
150+
case DAT__FILIN:
151+
trans = "File invalid (DAT__FILIN)";
152+
break;
153+
154+
case DAT__OBJIN:
155+
trans = "Object invalid (DAT__OBJIN)";
156+
break;
157+
158+
case DAT__GRPIN:
159+
trans = "Group invalid (DAT__GRPIN)";
160+
break;
161+
162+
case DAT__SUBIN:
163+
trans = "Subscripts invalid (DAT__SUBIN)";
164+
break;
165+
166+
case DAT__COMEX:
167+
trans = "Component already exists (DAT__COMEX)";
168+
break;
169+
170+
case DAT__OBJNF:
171+
trans = "Object not found (DAT__OBJNF)";
172+
break;
173+
174+
case DAT__TRUNC:
175+
trans = "Text truncated (DAT__TRUNC)";
176+
break;
177+
178+
case DAT__ACCON:
179+
trans = "Access conflict (DAT__ACCON)";
180+
break;
181+
182+
case DAT__CONER:
183+
trans = "Conversion error (DAT__CONER)";
184+
break;
185+
186+
case DAT__UNSET:
187+
trans = "Primitive data undefined (DAT__UNSET)";
188+
break;
189+
190+
case DAT__VERMM:
191+
trans = "Version mismatch (DAT__VERMM)";
192+
break;
193+
194+
case DAT__PRMAP:
195+
trans = "Primitive data mapped (DAT__PRMAP)";
196+
break;
197+
198+
case DAT__FILCK:
199+
trans = "File lock error (DAT__FILCK)";
200+
break;
201+
202+
case DAT__FILNF:
203+
trans = "File not found (DAT__FILNF)";
204+
break;
205+
206+
case DAT__FILPR:
207+
trans = "File protected (DAT__FILPR)";
208+
break;
209+
210+
case DAT__INCHK:
211+
trans = "Integrity check (DAT__INCHK)";
212+
break;
213+
214+
case DAT__FATAL:
215+
trans = "Fatal internal error (DAT__FATAL)";
216+
break;
217+
218+
case DAT__ISMAP:
219+
trans = "Data currently mapped (DAT__ISMAP)";
220+
break;
221+
222+
case DAT__BOUND:
223+
trans = "Outside bounds of object (DAT__BOUND)";
224+
break;
225+
226+
case DAT__FILCL:
227+
trans = "File close error (DAT__FILCL)";
228+
break;
229+
230+
case DAT__FILCR:
231+
trans = "File create error (DAT__FILCR)";
232+
break;
233+
234+
case DAT__FILMP:
235+
trans = "File mapping error (DAT__FILMP)";
236+
break;
237+
238+
case DAT__FILND:
239+
trans = "File not deleted (DAT__FILND)";
240+
break;
241+
242+
case DAT__FILNX:
243+
trans = "File not extended (DAT__FILNX)";
244+
break;
245+
246+
case DAT__FILRD:
247+
trans = "File read error (DAT__FILRD)";
248+
break;
249+
250+
case DAT__FILWR:
251+
trans = "File write error (DAT__FILWR)";
252+
break;
253+
254+
case DAT__NOMEM:
255+
trans = "Memory allocation error (DAT__NOMEM)";
256+
break;
257+
258+
case DAT__WLDIN:
259+
trans = "Wild card search context invalid (DAT__WLDIN)";
260+
break;
261+
}
262+
263+
/* If translation text was found, then determine the number of significant */
264+
/* characters to be returned and copy them to the output string. */
265+
if ( trans != NULL )
266+
{
267+
strcpy( msg_str, trans );
268+
*len = strlen( msg_str );
269+
}
270+
271+
/* If the error code is not a DAT__ error code, then use ems_ to translate */
272+
/* it as a system error code, and copy the resulting text to the output */
273+
/* string. */
274+
else
275+
{
276+
lstat = SAI__OK;
277+
emsMark( );
278+
emsSyser( "MESSAGE", status );
279+
emsMload( " ", "^MESSAGE", msg_str, &emslen, &lstat );
280+
*len = emslen;
281+
emsRlse( );
282+
}
283+
284+
/* Exit the routine. */
285+
return SAI__OK;
286+
}

0 commit comments

Comments
 (0)